package com.lb.jwitter.action;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import com.lb.jwitter.util.ApplicationContextProvider;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.lb.jwitter.service.ConditionReport;
import com.lb.jwitter.service.TblDKMHDotDK;
import com.lb.jwitter.service.TblDKMHDotDKService;
import com.lb.jwitter.service.TblQuyenChiTietService;
import com.lb.jwitter.service.TblTaiKhoan;
import com.lb.jwitter.service.TblDKMHDotDKHocVienChiTiet;
import com.lb.jwitter.service.TblDKMHDotDKHocVienChiTietService;
import com.lb.jwitter.service.TblDKMHDotDKHocVien;
import com.lb.jwitter.service.TblDKMHDotDKHocVienService;

/**
 * @author QUOCVIET
 * 
 */

@ContextConfiguration(locations = "classpath:beans.xml")
public class TblDKMHDotDKHocVienChiTietFormAction {
	private int pageSize;

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	private int page;

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	private int pages;

	public int getPages() {
		return pages;
	}

	public void setPages(int pages) {
		this.pages = pages;
	}

	private String dataString;

	public String getDataString() {
		return dataString;
	}

	private Collection<TblDKMHDotDKHocVienChiTiet> tblDKMHDotDKHocVienChiTiets;

	public Collection<TblDKMHDotDKHocVienChiTiet> getTblDKMHDotDKHocVienChiTiets() {
		return tblDKMHDotDKHocVienChiTiets;
	}

	private TblDKMHDotDKHocVienChiTietService tblDKMHDotDKHocVienChiTietService;

	private Collection<TblDKMHDotDKHocVien> tblDKMHDotDKHocViens;

	public Collection<TblDKMHDotDKHocVien> getTblDKMHDotDKHocViens() {
		return tblDKMHDotDKHocViens;
	}

	private List<TblDKMHDotDK> tblDKMHDotDKs;

	public List<TblDKMHDotDK> getTblDKMHDotDKs() {
		return tblDKMHDotDKs;
	}

	public void setTblDKMHDotDKs(List<TblDKMHDotDK> tblDKMHDotDKs) {
		this.tblDKMHDotDKs = tblDKMHDotDKs;
	}

	private TblDKMHDotDKHocVienService tblDKMHDotDKHocVienService;

	private TblTaiKhoan taiKhoanDangNhap;

	public TblTaiKhoan getTaiKhoanDangNhap() {
		return taiKhoanDangNhap;
	}

	public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) {
		this.taiKhoanDangNhap = taiKhoanDangNhap;
	}

	private TblQuyenChiTietService tblQuyenChiTietService;
	@Autowired
	// Injected by Spring
	ApplicationContextProvider contextProvider;

	public String execute() throws Exception {
		try {
			Map session = ActionContext.getContext().getSession();
			taiKhoanDangNhap = (TblTaiKhoan) session.get("taiKhoan");
			if (taiKhoanDangNhap == null)
				return "noprivilege";
			ApplicationContext context = ApplicationContextProvider
					.getApplicationContext();
			tblQuyenChiTietService = (TblQuyenChiTietService) context
					.getBean("tbl_Quyen_ChiTietClient");
			if (!tblQuyenChiTietService.checkRight(taiKhoanDangNhap
					.getMaNhomQuyen().getId(),
					"tbl_DKMH_DotDK_HocVien_ChiTiet", "xem")) {
				return "noprivilege";
			}

			tblDKMHDotDKHocVienChiTietService = (TblDKMHDotDKHocVienChiTietService) context
					.getBean("tbl_DKMH_DotDK_HocVien_ChiTietClient");
			tblDKMHDotDKHocVienService = (TblDKMHDotDKHocVienService) context
					.getBean("tbl_DKMH_DotDK_HocVienClient");
			TblDKMHDotDKService tblDKMHDotDKService = (TblDKMHDotDKService) context
					.getBean("tbl_DKMH_DotDKClient");

			List<ConditionReport> cons = new ArrayList<ConditionReport>();
			{
				ConditionReport con = new ConditionReport();
				con.setCol("id");
				con.setValue1("desc");
				con.setOperator("order");
				cons.add(con);
			}
			tblDKMHDotDKs = tblDKMHDotDKService.findtblDKMHDotDKByCondition(
					cons, 20, 1);

			dataString = "";
			dataString += "&tungayBatDau=";
			dataString += "&denngayBatDau=";
			dataString += "&tungayKetThuc=";
			dataString += "&denngayKetThuc=";
			dataString += "&quyen=";

			return Action.SUCCESS;
		} catch (Exception e) {
			System.out
					.println("Loi Form tbl_DKMH_DotDK_HocVien_ChiTiet Action");
			e.printStackTrace();
			return Action.ERROR;
		}
	}
}
